from common.base.base_handler import BaseHandler
from services.attenuators.model import Attenuators
from services.attenuators.schemas.configs import AttenuatorsConfig
from settings import settings


class AttenuatorsHandler(BaseHandler):
    __slots__ = ['model']

    async def handle_set_attenuators(self, params: dict) -> bool:
        config = AttenuatorsConfig(**params)
        self.model.att_configure(config)

        return True

    async def handle_get_attenuators(self) -> AttenuatorsConfig:
        return self.model.config

    async def handle_get_attenuator(self, params: dict) -> float:
        index = params['index']
        return self.model.config.values[index]

    def __init__(self) -> None:
        self.model = Attenuators()

        super(AttenuatorsHandler, self).__init__(request_queue_uuid=settings.ATTENUATORS_REQUEST_QUEUE)

        self.handle('set_attenuators', self.handle_set_attenuators)
        self.handle('get_attenuators', self.handle_get_attenuators)
        self.handle('get_attenuator', self.handle_get_attenuator)
